Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
d3plus-common
Advanced tools
Common functions and methods used across D3plus modules.
If you use NPM, run npm install d3plus-common --save
. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. You can also load directly from d3plus.org:
<script src="https://d3plus.org/js/d3plus-common.v0.7.full.min.js"></script>
Object.assign
.this
context.This is a global class.
# BaseClass.config([value]) <>
If value is specified, sets the methods that correspond to the key/value pairs and returns this class. If value is not specified, returns the current configuration.
This is a static method of BaseClass
, and is chainable with other methods of this Class.
# BaseClass.locale([value]) <>
Sets the locale used for all text and number formatting. This method supports the locales defined in d3plus-format. The locale can be defined as a complex Object (like in d3plus-format), a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale from d3plus-format.
This is a static method of BaseClass
, and is chainable with other methods of this Class.
{
separator: "",
suffixes: ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "B", "t", "q", "Q", "Z", "Y"],
grouping: [3],
delimiters: {
thousands: ",",
decimal: "."
},
currency: ["$", ""]
}
# BaseClass.on([typenames], [listener]) <>
Adds or removes a listener to each object for the specified event typenames. If a listener is not specified, returns the currently assigned listener for the specified event typename. Mirrors the core d3-selection behavior.
This is a static method of BaseClass
, and is chainable with other methods of this Class.
Param | Type |
---|---|
[typenames] | String |
[listener] | function |
By default, listeners apply globally to all objects, however, passing a namespace with the class name gives control over specific elements:
new Plot
.on("click.Shape", function(d) {
console.log("data for shape clicked:", d);
})
.on("click.Legend", function(d) {
console.log("data for legend clicked:", d);
})
# BaseClass.translate([value]) <>
Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.
This is a static method of BaseClass
, and is chainable with other methods of this Class.
For example, if we wanted to only change the string "Back" and allow all other string to return in English:
.translate(function(d) {
return d === "Back" ? "Get outta here" : d;
})
Wraps an object key in a simple accessor function.
This is a global function.
Param | Type | Description |
---|---|---|
key | String | The key to be returned from each Object passed to the function. |
[def] | * | A default value to be returned if the key is not present. |
this
accessor("id");
returns this
function(d) {
return d["id"];
}
A deeply recursive version of Object.assign
.
This is a global function. this
assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
returns this
{id: "bar", deep: {group: "A", value: 20}}
Applies each key/value in an object as an attr.
This is a global function.
Param | Type | Description |
---|---|---|
elem | D3selection | The D3 element to apply the styles to. |
attrs | Object | An object of key/value attr pairs. |
Finds the closest numeric value in an array.
This is a global function.
Param | Type | Description |
---|---|---|
n | Number | The number value to use when searching the array. |
arr | Array | The array of values to test against. |
Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' this
context.
This is a global function.
Param | Type | Default | Description |
---|---|---|---|
[config] | Object | this._shapeConfig | The configuration object to parse. |
[type] | String | "shape" | The event classifier to user for "on" events. For example, the default event type of "shape" will apply all events in the "on" config object with that key, like "click.shape" and "mouseleave.shape", in addition to any gloval events like "click" and "mouseleave". |
[nest] | String | An optional nested key to bubble up to the parent config level. |
Wraps non-function variables in a simple return function.
This is a global function. this
constant(42);
returns this
function() {
return 42;
}
Manages the enter/update/exit pattern for a single DOM element.
This is a global function.
Param | Type | Default | Description |
---|---|---|---|
selector | String | A D3 selector, which must include the tagname and a class and/or ID. | |
params | Object | Additional parameters. | |
[params.condition] | Boolean | true | Whether or not the element should be rendered (or removed). |
[params.enter] | Object | {} | A collection of key/value pairs that map to attributes to be given on enter. |
[params.exit] | Object | {} | A collection of key/value pairs that map to attributes to be given on exit. |
[params.parent] | D3Selection | d3.select("body") | The parent element for this new element to be appended to. |
[params.transition] | D3Transition | d3.transition().duration(0) | The transition to use when animated the different life cycle stages. |
[params.update] | Object | {} | A collection of key/value pairs that map to attributes to be given on update. |
Detects if a variable is a javascript Object.
This is a global function.
Combines an Array of Objects together and returns a new Object.
This is a global function.
Param | Type | Description |
---|---|---|
objects | Array | The Array of objects to be merged together. |
aggs | Object | An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values. |
this
merge([
{id: "foo", group: "A", value: 10, links: [1, 2]},
{id: "bar", group: "A", value: 20, links: [1, 3]}
]);
returns this
{id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}
Converts a string of directional CSS shorthand values into an object with the values expanded.
This is a global function.
Returns the appropriate CSS vendor prefix, given the current browser.
This is a global function.
Applies each key/value in an object as a style.
This is a global function.
Param | Type | Description |
---|---|---|
elem | D3selection | The D3 element to apply the styles to. |
styles | Object | An object of key/value style pairs. |
ES5 implementation to reduce an Array of values to unique instances.
This is a global function. this
unique(["apple", "banana", "apple"]);
returns this
["apple", "banana"]
This is a global function.
String constant used to reset an individual config property.
This is a global constant.
FAQs
Common functions and methods used across D3plus modules.
The npm package d3plus-common receives a total of 3,760 weekly downloads. As such, d3plus-common popularity was classified as popular.
We found that d3plus-common demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.